var lastValue = "", nodeList = [], fontCss = {};
var tloadinit;
ztreeLayerIframeOpenCloseUtils = {
	openIframeFromInfoByWH : function(openUrl,postUrl,formid,titles,w,h,refreshUrl,refreshNowUrl){
		//var titles = "给【"+rolename+"】分配权限";
		top.layer.open({
		  type: 2,
		  title: titles,
		  shade: 0.5,//背景色深度
		  fixed: false, //不固定
		  maxmin: true,
		  anim : 1,
		  shadeClose: false,//点击其它区域关闭
		  content:  openUrl,//'ztreeLayerIframeOpenCloseUtilsLayer.do?rid='+id,
		  area: [w+'px' , h+'px'],
		  btn : ["提交",'关闭'],
		  yes : function(index,layero){
			var body = top.layer.getChildFrame('body',index);
			var iframeWin = layero.find('iframe')[0];//得到iframe页的窗口对像，执行iframe页的方法，iframeWin.method();
			var values = iframeWin.contentWindow.ztreeLayerIframeAjaxPostUtils.doFormSubmitPost(postUrl,formid);
			if(values){
				var result = 0;
				var count = 0;
				var tmsg = top.layer.msg('数据提交中.......', {
					time : 100000,
					icon : 6
				});
				var tload = top.layer.load(0, {
					shade : [ 0.5, '#fff' ]
				}); // 0代表加载的风格，支持0-2
				ztreeLayerIframeOpenCloseUtils.asyncSaveCallBackIframeRefreshClose(iframeWin, index, result, 1000, count,tmsg, tload,refreshUrl,refreshNowUrl);
			}
		  },
		  end: function(index){
			  
		  }
		});  
	},
	browseOpenByWH : function(openUrl,titles,w,h){
		//var titles = title;//"浏览角色【"+rolename+"】权限";
		top.layer.open({
		  type: 2,
		  title: titles,
		  shade: 0.5,//背景色深度
		  fixed: false, //不固定
		  maxmin: true,
		  anim : 1,
		  shadeClose: false,//点击其它区域关闭
		  content:  openUrl,//'ztreeAsyncPostLayer.do?rid='+rid,
		  area: [w+'px' , h+'px'],
		  btn : ['关闭'],
		  end: function(index){
			  
		  }
		});  
	},
	asyncSaveCallBackIframeRefreshClose : function(iframeWin, index, result, time, count,tmsg, tload,refreshUrl,refreshNowUrl) {
		return setTimeout(function() {
			count++;
			result = iframeWin.contentWindow.ztreeLayerIframeAjaxPostUtils.asyncTreeCallResult();
			if (result == 1) {
				top.layer.msg('数据提交成功.......', {
					time : 2000,
					icon : 6
				});
				top.layer.close(index);
				top.layer.close(tmsg);
				top.layer.close(tload);
				var data = iframeWin.contentWindow.ztreeLayerIframeAjaxPostUtils.asyncTreeCallResultData();
				setTimeout(function(){
					$('#tree', parent.document).attr("src", refreshUrl+"&data=" + Math.random());
					window.location.href=refreshNowUrl+data; 
				} ,500);
			} else if(result == -1){
				if (count > 5) {
					top.layer.alert('数据提交失败....', {
						skin : 'layui-layer-lan',
						closeBtn : 0,
						anim : 4,
						icon : 5
					});
					top.layer.close(index);
					top.layer.close(tmsg);
					top.layer.close(tload);
				} else {
					ztreeLayerIframeOpenCloseUtils.asyncSaveCallBackIframeRefreshClose(iframeWin, index, result, (time + 1000), count,tmsg, tload,refreshUrl,refreshNowUrl);
				}
			}else if(result==-110){
				top.layer.close(tload);
				top.layer.alert('访问服务器接口出错....', {
					skin : 'layui-layer-lan',
					closeBtn : 0,
					anim : 4,
					icon : 5
				});
			}else{
				top.layer.close(tload);
				var error = iframeWin.contentWindow.ztreeLayerIframeAjaxPostUtils.asyncTreeCallResultError();
				top.layer.alert('操作失败。错误码：'+result+" 错误信息："+error, {
					skin : 'layui-layer-lan',
					closeBtn : 0,
					anim : 4,
					icon : 5
				});
			}
		}, time);
	},
	ztreeIframeNodeDeleteRefresh : function(data,delurl,treeid,treeurl,treeinfoid){
		var content = "<span style=\"color:red\">您确定要删除吗？</span>";
		top.layer.confirm(content,{
			btn:['删除','取消'],
			icon : 5
		},function(){
			// 删除动态
			var tload = top.layer.load(0, {
				shade : [ 0.5, '#fff' ]
			});
			$.ajax({
				type : "post",
				data : data,
				url : delurl,
				async : true,
				dataType : "json",
			}).done(function(data) {
				top.layer.close(tload);
				if (data != null) {
					if (data.ret == 1) {
						top.layer.msg('删除成功.......', {
							time : 1000,
							icon : 6
						});
						$(treeid, parent.document).attr("src", treeurl + Math.random());
						$(treeinfoid, parent.document).attr("src", "");
					} else {
						top.layer.alert('删除失败....' + data.msg, {
							skin : 'layui-layer-lan',
							closeBtn : 0,
							anim : 4,
							icon : 5
						});
					}
				}
			}).fail(function() {
				top.layer.close(tload);
				top.layer.alert('删除失败....', {
					icon : 5,
					skin : 'layui-layer-lan',
					closeBtn : 0,
					anim : 4
				});
			});
		},function(){
			
		});
	},
}
